package com.ruoyi.project.stock.info.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.stock.info.domain.StockInfo;
import com.ruoyi.project.stock.info.service.IStockInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * Roe股票列表Controller
 * 
 * @author ruoyi
 * @date 2020-07-26
 */
@Controller
@RequestMapping("/roe/info")
public class StockInfoController extends BaseController
{
    private String prefix = "roe/info";

    @Autowired
    private IStockInfoService stockInfoService;

    @RequiresPermissions("roe:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询Roe股票列表列表
     */
    @RequiresPermissions("roe:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockInfo stockInfo)
    {
        startPage();
        List<StockInfo> list = stockInfoService.selectStockInfoList(stockInfo);
        return getDataTable(list);
    }

    /**
     * 导出Roe股票列表列表
     */
    @RequiresPermissions("roe:info:export")
    @Log(title = "Roe股票列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockInfo stockInfo)
    {
        List<StockInfo> list = stockInfoService.selectStockInfoList(stockInfo);
        ExcelUtil<StockInfo> util = new ExcelUtil<StockInfo>(StockInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增Roe股票列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存Roe股票列表
     */
    @RequiresPermissions("roe:info:add")
    @Log(title = "Roe股票列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockInfo stockInfo)
    {
        return toAjax(stockInfoService.insertStockInfo(stockInfo));
    }

    /**
     * 修改Roe股票列表
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        StockInfo stockInfo = stockInfoService.selectStockInfoById(ID);
        mmap.put("stockInfo", stockInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存Roe股票列表
     */
    @RequiresPermissions("roe:info:edit")
    @Log(title = "Roe股票列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockInfo stockInfo)
    {
        return toAjax(stockInfoService.updateStockInfo(stockInfo));
    }

    /**
     * 删除Roe股票列表
     */
    @RequiresPermissions("roe:info:remove")
    @Log(title = "Roe股票列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockInfoService.deleteStockInfoByIds(ids));
    }
}
